{extend name="index/index" /}
{block name="main"}
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdn.bootcss.com/tinymce/4.4.3/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>

<div class="content-page">

    <div class="content">

        <div class="page-heading">
            <h1><i class='fa fa-table'></i>文章管理</h1>
            <h3>修改文章</h3></div>

        <div class="row">

            <div class="col-md-12">
                <div class="widget"  >
                    <div class="widget-header transparent" style="margin-bottom:30px;">
                        <h2><strong>Sortable</strong> Table</h2>

                    </div>
                    <div class="widget-content">
                    <form name="form1" id="form1" class="form-horizontal" action="{:url('admin/article/update',['id'=>$data['art_id']])}" method="post" enctype="multipart/form-data" >

                        <table class="table">
                            
                            <tr>
                                <th class="col-md-2">文章名称</th>
                                <td><input style="width:400px;" type='text' name='artname' value='{$data.artname}' /></td>

                            </tr>
                            <tr>
                                <th>文章类别 </th>
                                <td>
                                    <select class="form-control" name='column_id' style="width:100px;">
                                      <option value="3" {if condition="$data.column_id eq '3'"}selected{/if} >心情随笔</option>
                                      <option value="2" {if condition="$data.column_id eq '2'"}selected{/if} >韶华追忆</option>
                                      <option value="4" {if condition="$data.column_id eq '4'"}selected{/if} >技术分享</option>
                                      <option value="5" {if condition="$data.column_id eq '5'"}selected{/if} >技术探讨</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>文章图片</th>
                                <td>
                                    <!-- {$data.artcontent} -->
                                    <img id="img"  class="img-responsive" src='/static/upload/{$data.artpic}'>
                                    {$data.artcontent}
                                </td>
                            </tr>
                            <tr>
                                <th>上传新图片</th>
                                <td><input type='file'  name="photo" id="photo" /></td>
                            </tr>

                        </table>
                        



                        <textarea id="elm1" >Easy! You should check out MoxieManager!</textarea>
                        <input type='hidden' name='artcontent' value='' id='inputconc' placeholder=""></input>
                        <input type='hidden' name='arttext' value='' id='inputcont' placeholder=""></input>

                        <input type='hidden' name='artpic' value='' id='result' placeholder=""></input>
                        <!-- <input type="button" name="b1" value="更改图片" onclick="fsubmit()" class="btn btn-warning"> -->
                        <input  type="button" onclick= "doy()" value='发布' class="btn btn-info"/> 
                        <!-- <button type="button" class="btn btn-success" onclick="fsubmit()" >发布</button> -->
                    </form>
    
                </div>

            </div>
        </div>

    
    </div>

   

</div>

<script>
    function doy(){
        var tmpc= tinymce.get('elm1').getContent();      //此函数可获得编辑框内容   
        var tmpt= tinymce.get('elm1').getContent( { 'format' : 'text' } );      //此函数可获得纯文本  
        document.getElementById('inputconc').value = tmpc;
        document.getElementById('inputcont').value = tmpt;

        toastr.options = {
        closeButton: true,// 是否显示关闭按钮
        progressBar: true,// 实现显示计时条
        timeOut: "2000",// 自动关闭时间
        positionClass: "toast-top-right"// 提示位置
        // positionClass: "toast-top-full-width"// 提示位置
        // toast-top-full-width 顶端，宽度铺满整个屏幕
        // toast-top-right  顶端右边
        };



        function fsubmit(){
            var data = new FormData($('#form1')[0]);
            $.ajax({
                url: '/admin/article/server',
                type: 'POST',
                data: data,
                dataType: 'JSON',
                cache: false,
                processData: false,
                contentType: false
            }).done(function(ret){
                if(ret['isSuccess']){
                    // $('#result').html(ret['photo'] );
                    document.getElementById('result').value = ret['photo'];
                    toastr.success('修改文章成功');
                    setTimeout(function fun(){
                        $('#form1').submit();
                    },2000)
                    // alert('上传成功');

                }else{

                    toastr.success('修改纯文章成功');
                    setTimeout(function fun(){
                        $('#form1').submit();
                    },2000)
                    // alert('提交失敗');
                }
            });
            
        }
        fsubmit();
        
    }
  </script>

<script type="text/javascript">

    var img = $('#img').attr('src');
    var imgstr = img.substr('15');
    if(imgstr.length==0){
            $('#img').attr('style','display: none;');
    }

</script>

{/block}